import SwiftUI

// SellListRow
// 转一转商品展示

struct SellListRow: View {
    var book: Book_Sell
    
    var body: some View {
        HStack {
            let firstImageURL = book.imageId.first != nil ? URL(string: "http://62.234.45.120:1230/storage/bookImage/" + book.imageId.first! + ".jpeg") : URL(string: "http://62.234.45.120:1230/static/avatar/default.png")
            
            AsyncImage(url: firstImageURL) { image in
                image
                    .resizable()
                    .scaledToFit()
            } placeholder: {
                ProgressView()
            }
            .frame(width: 80, height: 80, alignment: .center)
            
            VStack(alignment: .leading, spacing: 8) {
                Text(book.bookName)
                
                Text(String(format: "¥%.2f", Double(book.requirePrice) / 100))
                    .foregroundColor(.orange)
                
                if(book.state == 1) {
                    Text("意向人数：\(book.tradeCount)人")
                        .foregroundColor(.accent)
                } else {
                    Text("已完成")
                        .foregroundColor(.accent)
                }
            }
        }
    }
}

#Preview {
    SellListRow(book: DefaultBook_Sell)
}
